package com.mrogrape.notepad.activity.action;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.TransferHandler;

import com.mrogrape.notepad.data.ViewContext;


public class MainFrameTransferHandler extends TransferHandler {

	/** serialVersionUID */
	private static final long serialVersionUID = 1L;

	@Override
	public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {						
		return true;							
	}								

	@SuppressWarnings("unchecked")								
	@Override								
	public boolean importData(JComponent comp, Transferable t) {								
		try {							
			if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {						
				List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);			
				for(File file : files){
					
					ViewContext.getMainFrame().createNewEditor(file);
				}
				return true;					
			}						
		} catch (UnsupportedFlavorException e) {							
			e.printStackTrace();						
		} catch (IOException e) {							
			e.printStackTrace();						
		}							
		return super.importData(comp, t);							
	}								

}
